<?php
//以前是专门按照中文去排序的
//$brand_result = mysql_query("select * from ".$table_Prefix."term where belong = 'brand' and interm = 'root' and publish = 1 order by CONVERT(name using gbk) asc ");
//20230831修改为按照英文名排序
$brand_result = mysql_query("select * from " . $table_Prefix . "brand where parent_id = 0 ");


?>
<div id="brand_list"></div>

<script>
    layui.use('tree', function () {
        var tree = layui.tree;


        //渲染
        var inst1 = tree.render({
            elem: '#brand_list',  //绑定元素
            showCheckbox: true,
            id: 'brand_list',
            checkChild: true,//是否联动子级节点,
            data: [
                <?php
                $i = 0;
                while ($brand = mysql_fetch_array($brand_result)) {


                //一级
                if ($i > 0) {
                    echo ',';
                }
                ?>
                {
                    title: <?php echo json_encode($brand['name']); ?>
                    , id: <?php echo $brand['nid']?>
                    , field: ''

                    <?
                    if (compare_term($brand['nid'], $brand_term_nid)) {
                    ?>
                    , spread: true
                    , checked: true

                <?php
                    }

                    $i++;
                    $brand2_result = mysql_query("select * from {$table_Prefix}brand where parent_id = '{$brand['nid']}' ");
                    if($brand2_result){
                    ?>
                    , children: [
                        <?php
                        $ii = 0;
                        while ($brand2 = mysql_fetch_array($brand2_result)) { //二级
                        if ($ii > 0) {
                            echo ',';
                        }
                        ?>
                        {
                            title: <?php echo json_encode($brand2['name']); ?>
                            , id: <?php echo $brand2['nid']?>
                            , field: ''
                            <? if (compare_term($brand2['nid'], $brand_term_nid)) {?>
                            , checked: true
                            , spread: true
                            <?php
                            }
                            $ii++;
                            $brand3_result = mysql_query("select * from " . $table_Prefix . "brand where  parent_id = '{$brand2['nid']}'");

                            if($brand3_result){
                            ?>
                            , children: [
                                <?php
                                $iii = 0;
                                while ($brand3 = mysql_fetch_array($brand3_result)) { //三级

                                if ($iii > 0) {
                                    echo ',';
                                }
                                ?>
                                {
                                    title: '<?php echo $brand3['name']?>'
                                    , id: <?php echo $brand3['nid']?>
                                    , field: ''
                                    <?
                                    if (compare_term($brand3['nid'], $brand_term_nid)) {
                                    ?>
                                    , spread: true
                                    <?php
                                    }
                                    ?>
                                }
                                <?php

                                $iii++;
                                }
                                ?>

                            ]
                        }
                        <?php
                        }
                        }
                        ?>
                    ]
                }
                <?php
                }
                }
                ?>

            ]
        });

    });


</script>

